package top.lunarye.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import top.lunarye.common.dto.EmailContentModel;
import top.lunarye.common.dto.SmsContentModel;

/**
 * @author lunar
 * @since 2022-07-11
 */
@Getter
@ToString
@AllArgsConstructor
public enum ChannelType {

    SMS(10, "短信", SmsContentModel.class, "sms"),
    Email(20, "电子邮件", EmailContentModel.class, "email");

    private Integer code;

    private String description;

    private Class contentModelClass;

    private String codeEn;

    /**
     * 通过code获取class
     * @param code
     * @return
     */
    public static Class getChanelModelClassByCode(Integer code) {
        ChannelType[] values = values();
        for (ChannelType value : values) {
            if (value.getCode().equals(code)) {
                return value.getContentModelClass();
            }
        }
        return null;
    }

    /**
     * 通过code获取enum
     * @param code
     * @return
     */
    public static ChannelType getEnumByCode(Integer code) {
        ChannelType[] values = values();
        for (ChannelType value : values) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }
}
